#include "Help.h"

void Help()
  {
    int Still = 1;
    while (Still)
      {
        OptHelpPage();
        OptHelpItem();
        HelpMouse(&Still);
        FlushBatchDraw();
      }
    OptMenuBk();
  }

void HelpMouse(int *Still)
  {
    MOUSEMSG mouse;
    mouse = GetMouseMsg();
    SelectHelpItem(mouse, Still);
  }

void SelectHelpItem(MOUSEMSG mouse, int *Still)
  {
    SelectBack2Menu(mouse, Still);
  }
void SelectBack2Menu(MOUSEMSG mouse, int *Still)
  {
    int InBk2MenuScope = 0;
    int static Bk2MenuAlerted = 0;
    IsInBk2MenuScope(mouse, &InBk2MenuScope);
    OutBk2MenuScope(&InBk2MenuScope, &Bk2MenuAlerted);
    LightBk2Menu(InBk2MenuScope, &Bk2MenuAlerted);
    Bk2MenuAlert(&Bk2MenuAlerted);
    PressBk2MenuButton(mouse, InBk2MenuScope, Still);
  }

void OptHelpPage()
  {
    IMAGE ImgHelpPage;
    loadimage(&ImgHelpPage, _T("Pic/Help/HelpPage.png"));
    TransparentImage(NULL, 0, 0, &ImgHelpPage);
  }
void OptHelpItem()
  {
    OptBk2MenuButton();
  }
void OptBk2MenuButton()
  {
    IMAGE ImgHelpBk2Menu;
    loadimage(&ImgHelpBk2Menu, _T("Pic/Help/HelpBk2Menu.png"));
    TransparentImage(NULL, 15, 60, &ImgHelpBk2Menu);
  }

void IsInBk2MenuScope(MOUSEMSG mouse, int *InBk2MenuScope)
  {
    // X: [15, 15+166]
    // Y:[57, 57+60]
    int X = mouse.x, Y = mouse.y;
    int DepX = 15, DepY = 60;
    if ((X >= DepX) && (X <= DepX + 166))
      if ((Y >= DepY) && (Y <= DepY + 60))
        *InBk2MenuScope = 1;
  }
void OutBk2MenuScope(int *InBk2MenuScope, int *Bk2MenuAlerted)
  {
    if (*InBk2MenuScope != 1)//Out of button
      *Bk2MenuAlerted = 0;
  }
void LightBk2Menu(int InBk2MenuScope, int *Bk2MenuAlerted)
  {
    int DepX = 15, DepY = 60;
    if (InBk2MenuScope)//Light
      {
        if (*Bk2MenuAlerted == 0)
          *Bk2MenuAlerted = 1;
        IMAGE Bk2MenuSelected;
        loadimage(&Bk2MenuSelected, _T("Pic/Help/HelpBk2MenuSelected.png"));
        TransparentImage(NULL, DepX, DepY, &Bk2MenuSelected);
      }
  }
void Bk2MenuAlert(int *Bk2MenuAlerted)
  {
    if (*Bk2MenuAlerted == 1)//Play sound
      {
        InScopeSound();
        *Bk2MenuAlerted = 2;
      }
  }
void PressBk2MenuButton(MOUSEMSG mouse, int InBk2MenuScope, int *Still)
  {
    if (InBk2MenuScope)
      if (mouse.uMsg == WM_LBUTTONDOWN)
        {
          PressHelpSound();
          *Still = 0;
        }
  }
